package com.weishu.file.rabbitmq;

import com.weishu.file.service.AliyunSmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * ExchangeTypes.DIRECT 交换机类型
 * aliMsgExchange交换机名称，发送消息时需要该参数
 * aliMsgQueue 队列名称，消费消息时需要该参数
 * aliMsgRoutingKey 发送消息时，需要该参数
 */
@Component
@RabbitListener(bindings = @QueueBinding(
		value = @Queue(value = "ThreeGroups", autoDelete = "false"),
		exchange = @Exchange(value = "aliMsgExchange", type = ExchangeTypes.DIRECT, durable = "true"),
		key = "aliMsgRoutingKey"))
public class AliMsgReceiver {

	protected Logger logger = LoggerFactory.getLogger(AliMsgReceiver.class);
	
	@Autowired
	AliyunSmsService aliyunSmsService;
	
	@RabbitHandler
    public void processMsg(Map<String,Object> msg) {
		String phoneNum = msg.get("phoneNum").toString();
		aliyunSmsService.sendVerifyCode(phoneNum);
		logger.info("aliMsgQueue:{} ok!",msg);
    }
}
